package cn.com.generaldata.os.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.Exps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorInfo;
import cn.com.generaldata.os.vo.ResultVO;

/**
 * 指标信息service.
 */
@Service
public class IndicatorInfoService {

	@Autowired
	private Dao dao;

	/**
	 * 构造统计制度map.
	 * 
	 * @return
	 */
	public Map<Integer, String> getStatSystems() {

		return null;
	}

	/**
	 * 查询指标信息
	 * 
	 * @param statSystem 统计制度
	 * @param name 指标名称
	 * @param code 指标代码
	 * @return
	 */
	public QueryResult queryIndicator(int statSystem, String industryCode, String name, String code, int pageNum) {
		Criteria cri = Cnd.cri();
		cri.where().and("indicatorType", "=", statSystem);

		if (StringUtils.isNotBlank(industryCode)) {
			cri.where().and(Exps.like("industryCode", industryCode, false).left(""));
		}

		if (StringUtils.isNotBlank(name)) {
			cri.where().and(Exps.like("name", name, false));
		}

		if (StringUtils.isNotBlank(code)) {
			cri.where().and(Exps.like("code", code, false));
		}

		QueryResult result = new QueryResult();
		Pager pager = dao.createPager((pageNum < 1) ? 1 : pageNum, ResultVO.DEFAULT_PAGE_SIZE);

		List<IndicatorInfo> results = dao.query(IndicatorInfo.class, cri, pager);
		result.setList(results);

		int count = dao.count(IndicatorInfo.class, cri);
		pager.setRecordCount(count);

		result.setPager(pager);
		return result;
	}
}
